//!\file backtracer_log.c

#include <assert.h>
#include <errno.h>
#include <string.h>

#include "log.h"
#include "check.h"
#include "errors.h"

//------------------------------------------------------------------------------

void LogPrintf(const char* format, ...) {
    FILE* pfile = _LogGetSetPlogFile(NULL);
    CHECK_DBG_ERR(pfile, CANNOT_GET_STORED_ARG);

    va_list arg;
    va_start(arg, format);
    vfprintf((FILE*) pfile, format, arg);
    fflush(pfile);
    va_end(arg);
}


//------------------------------------------------------------------------------

TBGError InitLog(FILE* plog) {
    TBGError ret = 0;
    CHECK_RET(plog, INVALID_FILE, exit_point, ret);
    _LogGetSetPlogFile(plog);

exit_point:
    return ret;
}

//------------------------------------------------------------------------------

FILE* _LogGetSetPlogFile(FILE* pfile) {
    static FILE *pfile_;
    if(pfile)
        pfile_ = pfile;
    CHECK_DBG_ERR(pfile_, CANNOT_GET_STORED_ARG);
    return pfile_;
}

